<template>
  <div>
    <!-- 待回运旧件查询 - 编辑页面 -->
    <BreakSpace label="索赔单信息" :containerStyle="{ marginBottom: '10px' }"/>
    <FormPanel ref="formPanel1" :list="formList" :cols="2" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
    <div style="padding-top: 3rem;"></div>
    <BreakSpace label="保修旧件列表" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table1"
      :columns="columns"
      :params="fetchParams"
      :dataSource="dataList"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      height="auto"
      :isPagination=false
      :isSelectColumn=false
    >
    </FilterTable>
    <div style="padding-top: 3rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button  @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
import { getPartType } from '@/api/dictionary/index.js';
import { getReturnDetailByClaimId ,selectById } from '@/api/usedPartsReturnManage/usedPartsReturn_DLR/usedPartsWaitReturnQuery';
import { dictionary } from '@/utils/dictMixin';


export default {
  props: ['rowData'],
  mixins: [dictionary],
  data() {
    return {
      dataList: [],
      huanxiajiandataList: [],
      fujiaxiangmudataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      columns: this.creatHeader(),
      flterValue: {}, //参数
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中服务站
      formList: this.createFormList(),
      saveData: null
    };
  },
  created() {
    this.chuqi3();
    this.init(this.rowData);
  },
  methods: {
    async init(val) {
      let newVar = await getReturnDetailByClaimId({claimId: val});
      this.editData = newVar.data;
      console.log("=== 通过ID查询结果返回 ==== ",newVar," ======");
      this.formList.forEach(x => {
        console.log(newVar);
        x.initialValue = newVar.data[x.fieldName];
      });
      this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(newVar.data.partList);

    },
    //索赔类型下拉框
    async chuqi3() {
      console.log("===== 获取下拉框数据 ====== ")
      const res = await getPartType({ type: 5501 });
      console.log("==========",res)
      if (res.resultCode == 200) {
        this.formList.find(x => x.fieldName == 'cmsClaimType').initialValue = '';
        this.formList.find(x => x.fieldName == 'cmsClaimType').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
      }
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      this.$refs.formPanel1.SUBMIT_FORM();
      if (this.saveData) {
        this.$emit('save', this.selectedRows);
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close');
    },
    chooseOrderNo() {
      this.visible = true;
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '服务站代码',
          fieldName: 'ownerCode',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '服务站名称',
          fieldName: 'ownerName',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'SELECT',
          label: '索赔类型',
          fieldName: 'cmsClaimType',
          itemList: [],
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '车型代码',
          fieldName: 'modelCode',
          placeholder: '请输入车型...',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '索赔单号',
          fieldName: 'claimNo',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '供应商代码',
          fieldName: 'supCode',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '供应商名称',
          fieldName: 'supName',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'DATE',
          label: '购车日期',
          fieldName: 'saleDate',
          valueFormat: 'yyyy-MM-dd',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'driveMile',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '故障现象代码',
          fieldName: 'faultCode',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '故障现象名称',
          fieldName: 'faultName',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '故障原因代码',
          fieldName: 'frCode',
          readonly: true, // 只读
          disabled: true //置灰
        },
        {
          type: 'INPUT',
          label: '故障原因名称',
          fieldName: 'frName',
          readonly: true, // 只读
          disabled: true //置灰
        },
        // {
        //   type: 'INPUT',
        //   label: '检查结果',
        //   fieldName: 'partStatus222',
        //   readonly: true // 只读
        // }
      ];
    },
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '索赔单号', dataIndex: 'claimNo', sorter: true},
        {title: '维修单号', dataIndex: 'roNo', sorter: true},
        {title: '旧件id', dataIndex: 'partId', sorter: true, hidden: true},
        {title: '旧件代码', dataIndex: 'partCode', sorter: true},
        {title: '旧件名称', dataIndex: 'partName', sorter: true},
        {title: '回运数量', dataIndex: 'partCount', sorter: true, width: 100},
        {title: 'VIN', dataIndex: 'vin', sorter: true, width: 150},
        {title: '返件类型', dataIndex: 'returnType', sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.returnType, '5585')}</span>;
          }}
      ];
    },
  }
};
</script>
<style lang="less" scoped></style>
